// https://nuxt.com/docs/api/configuration/nuxt-config
import { loadEnv } from "vite";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import path from "path";

// 通过启动命令区分环境，加载env
const envScript = (process.env as any).npm_lifecycle_script.split(" ");
const envName = envScript[envScript.length - 1];
const envObj: any = { dev: "development", product: "production" };
const envData = loadEnv(
    envObj.hasOwnProperty(envName) ? envObj[envName] : envName,
    ""
);

export default defineNuxtConfig({
    app: {
        baseURL: "/pc/",
    },
    modules: [
        "@nuxtjs/i18n",
        "@pinia/nuxt",
        "@element-plus/nuxt",
        "@nuxtjs/tailwindcss",
    ],
    css: ["@/assets/styles/index.scss", "element-plus/theme-chalk/index.css"],
    i18n: {
        langDir: "./locale/",
        defaultLocale: "zh-cn",
        locales: [
            { code: "zh-cn", iso: "CN", file: "zh-cn.json" },
            { code: "en", iso: "GB", file: "en.json" },
        ],
        strategy: 'no_prefix',
    },
    vite: {
        plugins: [
            createSvgIconsPlugin({
                iconDirs: [path.resolve(process.cwd(), "assets/icons")],
                symbolId: "local-icon-[name]",
            }),
        ],
    },
    runtimeConfig: {
        public: envData,
    },
    telemetry: false,
    ssr: false,
});
